﻿Imports System.Data.SqlClient

Public Class clsOPERACIONES
     
    Public Function Insertar(ByVal CLAVE As String, ByVal NOMBRE As String, ByVal DEPARTAMENTO As String, ByVal CAPACIDAD As Double, ByVal PIEZAS_HORA As Double, ByVal HORAS_PIEZA As Double, ByVal MAQUINA As String, ByVal VARIABLE As Double, ByVal FIJO As Double, ByVal HORAS As Double)
        Dim sql As String = "Insert Into OPERACIONES " & _
                            "VALUES (" & _
                            "@CLAVE," & _
                            "@NOMBRE_OPERACION," & _
                            "@CLAVE_DEPTO," & _
                            "@DEPARTAMENTO," & _
                            "@ESTATUS," & _
                            "@CAPACIDAD," & _
                            "@PIEZA_HORA," & _
                            "@HORAS_PIEZA," & _
                            "@MAQUINA," & _
                            "@COSTO_FIJO," & _
                            "@COSTO_VAR," & _
                            "@HORAS_BASE) " & _
                            " SELECT SCOPE_IDENTITY()"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CLAVE", CLAVE)
        Command.Parameters.AddWithValue("NOMBRE_OPERACION", NOMBRE)
        Command.Parameters.AddWithValue("CLAVE_DEPTO", BuscarStrDatoCitra("SELECT CLAVE FROM DEPARTAMENTOS WHERE NOMBRE='" & DEPARTAMENTO & "'"))
        Command.Parameters.AddWithValue("DEPARTAMENTO", DEPARTAMENTO)
        Command.Parameters.AddWithValue("ESTATUS", 1)
        Command.Parameters.AddWithValue("CAPACIDAD", CAPACIDAD)
        Command.Parameters.AddWithValue("PIEZA_HORA", PIEZAS_HORA)
        Command.Parameters.AddWithValue("HORAS_PIEZA", HORAS_PIEZA)
        Command.Parameters.AddWithValue("MAQUINA", MAQUINA)
        Command.Parameters.AddWithValue("COSTO_FIJO", FIJO)
        Command.Parameters.AddWithValue("COSTO_VAR", VARIABLE)
        Command.Parameters.AddWithValue("HORAS_BASE", HORAS)

        cnConn.Open()

        Try
            Insertar = Convert.ToInt32(Command.ExecuteScalar)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try


    End Function
    Public Function Actualizar(ByVal CLAVE As String, ByVal NOMBRE As String, ByVal DEPARTAMENTO As String, ByVal CAPACIDAD As Double, ByVal PIEZAS_HORA As Double, ByVal HORAS_PIEZA As Double, ByVal MAQUINA As String, ByVal VARIABLE As Double, ByVal FIJO As Double, ByVal HORAS As Double)
        Dim sql As String = "UPDATE OPERACIONES SET " & _
                            "NOMBRE_OPERACION=@NOMBRE_OPERACION," & _
                            "CLAVE_DEPTO=@CLAVE_DEPTO," & _
                            "DEPARTAMENTO=@DEPARTAMENTO," & _
                            "CAPACIDAD=@CAPACIDAD," & _
                            "PIEZA_HORA=@PIEZA_HORA," & _
                            "HORAS_PIEZA=@HORAS_PIEZA," & _
                            "MAQUINA=@MAQUINA," & _
                            "COSTO_FIJO=@COSTO_FIJO," & _
                            "COSTO_VAR=@COSTO_VAR," & _
                            "HORAS_BASE=@HORAS_BASE " & _
                            "WHERE CLAVE=@CLAVE"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CLAVE", CLAVE)
        Command.Parameters.AddWithValue("NOMBRE_OPERACION", NOMBRE)
        Command.Parameters.AddWithValue("CLAVE_DEPTO", BuscarStrDatoCitra("SELECT CLAVE FROM DEPARTAMENTOS WHERE NOMBRE='" & DEPARTAMENTO & "'"))
        Command.Parameters.AddWithValue("DEPARTAMENTO", DEPARTAMENTO)
        Command.Parameters.AddWithValue("CAPACIDAD", CAPACIDAD)
        Command.Parameters.AddWithValue("PIEZA_HORA", PIEZAS_HORA)
        Command.Parameters.AddWithValue("HORAS_PIEZA", HORAS_PIEZA)
        Command.Parameters.AddWithValue("MAQUINA", MAQUINA)
        Command.Parameters.AddWithValue("COSTO_FIJO", FIJO)
        Command.Parameters.AddWithValue("COSTO_VAR", VARIABLE)
        Command.Parameters.AddWithValue("HORAS_BASE", HORAS)


        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try


    End Function
   
End Class


